
#include "http_context.h"
#include "http_request.h"
#include "zmalloc.h"
#include "mylog.h"

#include <stdio.h>

static int contextId = 0;
struct HttpContext* initHttpContext() {
	struct HttpContext* httpContext = (struct HttpContext* ) zcalloc(sizeof(struct HttpContext));
	if (!httpContext) {
		return NULL;
	}

	httpContext->state = ExpectRequestLine;
	httpContext->httpRequest = initHttpRequest(UnKnownRequest);
	if (!httpContext->httpRequest) {
		zfree(httpContext);
		return NULL;
	}

	httpContext->id = ++contextId;
	mylog(LOG_INFO, "INIT httpContext[%d]", httpContext->id);
	return httpContext;
}

void destroyHttpContext(struct HttpContext* httpContext) {
	if (!httpContext) {
		return;
	}
	mylog(LOG_INFO, "detroyHttpContext[%d]", httpContext->id);
	if (httpContext->httpRequest) {
		destoryHttpRequest(httpContext->httpRequest);
	}

	zfree(httpContext);
	return;
}
